package com.sangmo.fts.process.storage.model;

import com.sangmo.boot.framework.data.entity.general.SoftDeleteEntity;
import com.sangmo.boot.framework.data.json.meta.ExtView;
import com.sangmo.boot.framework.data.json.meta.Formula;
import com.sangmo.boot.framework.data.json.meta.One;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataField;
import com.sangmo.boot.framework.plugin.dataview.def.meta.DataView;
import com.sangmo.fts.basic.model.Company;
import com.sangmo.fts.common.IConstants;
import com.sangmo.fts.process.storage.calculator.CsfRepaymentAmountCalculator;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLDeleteAll;
import org.hibernate.annotations.Where;

import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import java.util.Date;

@Entity
@Table(name = "csf_loan")
@DataView
@ExtView
@Formula(value = "repaymentAmount",calc = CsfRepaymentAmountCalculator.class, groups = {"CsfLoan.search","CsfLoan.detail"})
@SQLDelete(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@SQLDeleteAll(
        sql = "UPDATE #{entityName} SET deleted = CURRENT_TIMESTAMP WHERE id = ?"
)
@Where(
        clause = "deleted = 0"
)
public class CsfLoan extends SoftDeleteEntity {

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long trainingId;

    @DataField(value = IConstants.DATA_TYPE.STRING_50,required = true, index = true, unique = true)
    private String applyCode;

    @DataField(value = IConstants.DATA_TYPE.STRING_10)
    private String acceptCode;

    @DataField(value = IConstants.DATA_TYPE.STRING_50)
    private String code;

    @One(value = "applyCompany", target = Company.class, fieldset = {"id", "name"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long applyId;

    @One(value = "contract", target = CsfContract.class, groups = {"CsfLoan.search","CsfLoan.detail","CsfDraft.selection"})
    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long contractId;

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true)
    private Long agreementId;

    @One(value = "assurance", target = CsfAssurance.class, groups = {"CsfLoan.search","CsfLoan.detail"})
    private Long assuranceId;

    @DataField(value = IConstants.DATA_TYPE.LONG, required = true, index = true)
    private Long bankId;

    private BigDecimal amount;

    private BigDecimal ratio;

    private BigDecimal deposit;

    private Date startTime;

    private Date endTime;

    @DataField(value = IConstants.CSF_LOAN_DATA_TYPE.LOAN_DURATION, required = true)
    private String duration;

    @DataField(value = IConstants.CSF_LOAN_DATA_TYPE.LOAN_STATE, required = true, index = true)
    private String state = States.ACCEPTING;

    private String auditMind;

    private Date auditTime;

    private Long auditBy;

    @DataField(index = true)
    private boolean settled;

    public Long getTrainingId() {
        return trainingId;
    }

    public void setTrainingId(Long trainingId) {
        this.trainingId = trainingId;
    }

    public String getAcceptCode() {
        return acceptCode;
    }

    public void setAcceptCode(String acceptCode) {
        this.acceptCode = acceptCode;
    }

    public String getApplyCode() {
        return applyCode;
    }

    public void setApplyCode(String applyCode) {
        this.applyCode = applyCode;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public Long getApplyId() {
        return applyId;
    }

    public void setApplyId(Long applyId) {
        this.applyId = applyId;
    }

    public Long getContractId() {
        return contractId;
    }

    public void setContractId(Long contractId) {
        this.contractId = contractId;
    }

    public Long getAgreementId() {
        return agreementId;
    }

    public void setAgreementId(Long agreementId) {
        this.agreementId = agreementId;
    }

    public Long getAssuranceId() {
        return assuranceId;
    }

    public void setAssuranceId(Long assuranceId) {
        this.assuranceId = assuranceId;
    }

    public Long getBankId() {
        return bankId;
    }

    public void setBankId(Long bankId) {
        this.bankId = bankId;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    public BigDecimal getRatio() {
        return ratio;
    }

    public void setRatio(BigDecimal ratio) {
        this.ratio = ratio;
    }

    public BigDecimal getDeposit() {
        return deposit;
    }

    public void setDeposit(BigDecimal deposit) {
        this.deposit = deposit;
    }

    public Date getStartTime() {
        return startTime;
    }

    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    public Date getEndTime() {
        return endTime;
    }

    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    public String getDuration() {
        return duration;
    }

    public void setDuration(String duration) {
        this.duration = duration;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getAuditMind() {
        return auditMind;
    }

    public void setAuditMind(String auditMind) {
        this.auditMind = auditMind;
    }

    public Date getAuditTime() {
        return auditTime;
    }

    public void setAuditTime(Date auditTime) {
        this.auditTime = auditTime;
    }

    public Long getAuditBy() {
        return auditBy;
    }

    public void setAuditBy(Long auditBy) {
        this.auditBy = auditBy;
    }

    public boolean isSettled() {
        return settled;
    }

    public void setSettled(boolean settled) {
        this.settled = settled;
    }

    public interface Duration {
        String ONE_MONTH = "ONE_MONTH"; //1个月
        String THREE_MONTH = "THREE_MONTH"; //3个月
        String SIX_MONTH = "SIX_MONTH"; //6个月
    }

    public interface States {
        String ACCEPTING = "ACCEPTING"; //待受理
        String PENDING = "PENDING"; //待审核/已受理
        String CONFIRMED = "CONFIRMED"; //审核通过/贷放款
        String REJECTED = "REJECTED"; //已驳回
    }

    public interface ICsfLoanRepaymentCalculator {

    }
}
